public class App {
    private static int MAX=8;
    private static int[] arr=new int[MAX];
    private static int count=0;
    //定义数组 array, 保存皇后放置位置的结果,比如 arr = {0 , 4, 7, 5, 2, 6, 1, 3}

    public static void main(String[] args) throws Exception {
        //System.out.println("Hello, World!");
        check(0);
        System.out.println("解法总数："+count);
    }
    private static void print(){
        for(int i=0;i<arr.length;i++){
            System.out.print(arr[i]+" ");
        }
        System.out.println("");
    }
    private static boolean judge(int n){
        for(int i=0;i<n;i++){
            if(arr[i]==arr[n]||Math.abs(n-i)==Math.abs(arr[n]-arr[i])){
                return false;
            }
        }
        return true;
    }
    private static void check(int n){
        if(n==MAX){
            print();
            count++;
            return;
        }else{
            for(int i=0;i<MAX;i++){
                arr[n]=i;
                if(judge(n)){
                    check(n+1);
                }
            }
        }
    }
}
